﻿using Mapster;
using WeChatV3Pay.Application.Refunds.Dtos;
using WeChatV3Pay.Application.Transactions.Dtos.JsApi;

namespace WeChatV3Pay.Services
{
    public class Mapper : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            config.ForType<JSBridgeRes, WeixinJSBridgeResponse>()
                .Map(dest => dest.AppId, src => !string.IsNullOrWhiteSpace(src.AppId) ? src.AppId : "")
                .Map(dest => dest.NonceStr, src => !string.IsNullOrWhiteSpace(src.NonceStr) ? src.NonceStr : "")
                .Map(dest => dest.Package, src => !string.IsNullOrWhiteSpace(src.Package) ? src.Package : "")
                .Map(dest => dest.TimeStamp, src => !string.IsNullOrWhiteSpace(src.TimeStamp) ? src.TimeStamp : "")
                .Map(dest => dest.SignType, src => !string.IsNullOrWhiteSpace(src.SignType) ? src.SignType : "")
                .Map(dest => dest.PaySign, src => !string.IsNullOrWhiteSpace(src.PaySign) ? src.PaySign : "");


            config.ForType<RefundsRes, RefundsResponse>()
               .Map(dest => dest.TransactionId, src => !string.IsNullOrWhiteSpace(src.TransactionId) ? src.TransactionId : "")
               .Map(dest => dest.OutTradeNo, src => !string.IsNullOrWhiteSpace(src.OutTradeNo) ? src.OutTradeNo : "")
               .Map(dest => dest.OutRefundNo, src => !string.IsNullOrWhiteSpace(src.OutRefundNo) ? src.OutRefundNo : "")
               .Map(dest => dest.Channel, src => !string.IsNullOrWhiteSpace(src.Channel) ? src.Channel : "")
               .Map(dest => dest.UserReceivedAccount, src => !string.IsNullOrWhiteSpace(src.UserReceivedAccount) ? src.UserReceivedAccount : "")
               .Map(dest => dest.CreateTime, src => !string.IsNullOrWhiteSpace(src.CreateTime) ? src.CreateTime : "")
               .Map(dest => dest.SuccessTime, src => !string.IsNullOrWhiteSpace(src.SuccessTime) ? src.SuccessTime : "")
               .Map(dest => dest.Code, src => !string.IsNullOrWhiteSpace(src.Code) ? src.Code : "")
               .Map(dest => dest.Status, src => !string.IsNullOrWhiteSpace(src.Status) ? src.Status : "")
                .Map(dest => dest.FundsAccount, src => !string.IsNullOrWhiteSpace(src.FundsAccount) ? src.FundsAccount : "")
               .Map(dest => dest.Message, src => !string.IsNullOrWhiteSpace(src.Message) ? src.Message : "")
               .Map(dest => dest.RefundId, src => !string.IsNullOrWhiteSpace(src.RefundId) ? src.RefundId : "");


            config.ForType<QueryTransactionRes, QueryTransactionResponse>()
              .Map(dest => dest.TradeState, src => !string.IsNullOrWhiteSpace(src.TradeState) ? src.TradeState : "")
              .Map(dest => dest.TradeStateDesc, src => !string.IsNullOrWhiteSpace(src.TradeStateDesc) ? src.TradeStateDesc : "")
              .Map(dest => dest.SuccessTime, src => !string.IsNullOrWhiteSpace(src.SuccessTime) ? src.SuccessTime : "")
              .Map(dest => dest.Code, src => !string.IsNullOrWhiteSpace(src.Code) ? src.Code : "")
              .Map(dest => dest.Message, src => !string.IsNullOrWhiteSpace(src.Message) ? src.Message : "");
        }
    }
}
